package com.zhu.day.controller;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;
import java.util.*;

public class CheckList {

    public static void main(String[] args) {
//        String nowName = "big.txt";
//        nowName = "little.txt";
//        CheckList ck = new CheckList();
//        List<String> list = ck.readFile(nowName);
//        System.out.println("==="+list.size());
//        List<List<String>> partition = Lists.partition(list, 200);
//        for (List<String> strings : partition) {
//            System.out.println(JSON.toJSONString(strings));
//        }
        final List<Integer> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            list.add(i);
        }
        List<Integer> list1 = list;
        List<Integer> list3 =  new ArrayList<>();
        list3.add(1);
        list3.add(2);

        list1.removeAll(list3);
//        Set<String> randoms = createRandoms(list, 10);
        System.out.println(JSON.toJSONString(list));
        System.out.println(JSON.toJSONString(list1));
        System.out.println(JSON.toJSONString(list3));
    }

    private List<String> readFile(String nowName) {
        String filePath = CheckList.class.getClassLoader().getResource(nowName).getPath();
        try {
            List<String> list1 = new ArrayList<>();
            List<String> list = Files.readLines(new File(filePath), Charsets.UTF_8);
            list.stream().forEach(line -> {
                String[] s = line.split("\t");
                String starid = s[0];
                list1.add(starid.trim());
            });
            int size = list1.size();
            System.out.println("readFile.count:"+size);
            return list1;
        } catch (IOException e) {
           e.printStackTrace();
        }
        return new ArrayList<>();
    }


    public static Set<String> createRandoms(List<String> list, int n) {
        Map<Integer, String> map = new HashMap();
        Set<String> news = new HashSet<>();
        if (list.size() <= n) {
            return new HashSet<>(list);
        } else {
            while (map.size() < n) {
                int random = (int) (Math.random() * list.size());
                if (!map.containsKey(random)) {
                    map.put(random, "");
                    news.add(list.get(random));
                }
            }
            return news;
        }
    }
}
